﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WheelFunc : ItemFunc
{
    // Start is called before the first frame update 
    private JointMotor2D JointMotor;
    public float MotorSpeed;
    public float MaxMotorForce;
    /// <summary>
    /// 是不是往右走
    /// </summary>
    protected bool IfRight;
    public override void Awake()
    {
        base.Awake();
        JointMotor = this.transform.Find("Collider").GetComponentInChildren<WheelJoint2D>().motor;

    }

    public override void KeyOnInvoke()
    {
        base.KeyOnInvoke();
        if (IfRight == true)
        {
            JointMotor.motorSpeed = Mathf.Abs(MotorSpeed);
        }
        else
        {
            JointMotor.motorSpeed = -Mathf.Abs(MotorSpeed);
        }
            JointMotor.maxMotorTorque = MaxMotorForce;
        this.transform.Find("Collider").GetComponentInChildren<WheelJoint2D>().motor = JointMotor;
    }
    public override void KeyUpInvoke()
    {
        base.KeyUpInvoke();
        JointMotor.motorSpeed = 0;
        this.transform.Find("Collider").GetComponentInChildren<WheelJoint2D>().motor = JointMotor;
    }

}
